<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> 
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>caregory</title>

	<link rel="stylesheet" type="text/css" media="all" href="<c:url value="/styles/style.css"/>" />
	<link rel="stylesheet" type="text/css" media="all" href="<c:url value="/styles/elastic/elastic.css"/>" />
	<link rel="stylesheet" type="text/css" href="<c:url value="/styles/jquery-ui/smoothness/jquery-ui-1.8.custom.css"/>"  />

	<script src="<c:url value="/scripts/jquery-1.4.2.js"/>" type="text/javascript" language="javascript" charset="utf-8"></script>
	<script src="<c:url value="/scripts/json.min.js"/>" type="text/javascript"></script>

<script type="text/javascript">	
	$(document).ready(function() {

		$("#rootCategory").change( function() {
			$.getJSON("children", { id: $('#rootCategory').val() }, function( data ) {
				if (data.length > 0) {

				} else {
					alert($("#rootCategory").val());
					$("#parent_id").val( $("#rootCategory").val() );
				}
			});
		});
		
		$("#umanji_category").submit( function() {
			var category = $(this).serializeObject();
			$.post("create", category, function(data){
					     alert("Data Loaded: " + data);
			});
			return false;
		});
	});
</script>

</head>
<body>
  
<div id="target">

</div>

	<div>
		<label for="CategoryName">루트 카테고리:</label>
		<select id="rootCategory" name="rootCategory">
			<c:forEach items="${umj_root_category}" var="rootCategory" varStatus="status">
				<option value="<c:out value="${rootCategory.id}" escapeXml="false"/>">
				<c:out value="${rootCategory.categoryName}" escapeXml="false"/>
				</option>
			</c:forEach>
		</select>
	</div>

<form:form modelAttribute="umanji_category" method="POST">
	<fieldset>
	<legend>카테고리 등록화면</legend>
	<input type="hidden" value="" name="parent_id" id="parent_id" />"
	<form:errors path="*" cssClass="errors"/>
	<div>
		<label for="CategoryName">카테고리 명 : </label>
		<form:input cssStyle="width:200px" maxlength="30" path="CategoryName" size="30"/>
		<form:errors path="CategoryName" cssClass="errors"/>

		<label for="CategoryName">카테고리 코드 : </label>
		<form:input cssStyle="width:100px" maxlength="30" path="CategoryCode" size="30"/>
		<form:errors path="CategoryCode" cssClass="errors"/>

		<label for="CategoryName">카테고리 정렬 순서 : </label>
		<form:input cssStyle="width:30px" maxlength="3" path="CategoryOrder" size="3"/>
		<form:errors path="CategoryOrder" cssClass="errors"/>
	</div>
	<p>
		<input id="create" type="submit" value="Create" />
	</p>
	</fieldset>
</form:form>
</body>
</html>